home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
FUMBLE_F
/
FUMBLE_F.C
next >
Wrap
C/C++ Source or Header
|
1990-11-26
|
3KB
|
97 lines
#include "SetupA4.h"
#define TRAPNUM 0x01DC
/*** The following is my first attempt at an Init. It was written using
*** Think C. I make no promises that it's entirely correct, but it seems
*** to work. Feel free to use any of this to make other interesting Inits.
*** This init watches for the string in the 'STR ' resource "Old String"
*** to be typed and replaces it with what's in the resource "New String".
***
*** Send any comments to:
*** Brad Quick Software
*** PO Box 231
*** Staatsburg, NY 12580
*** GEnie: BSQ
***/
typedef void (*fptr)(); /* pointer to a function */
pascal void myproc(int,TEHandle);
long address; /*** stored address of TEKey trap ***/
int pos; /*** position in old string of next character we're waiting for ***/
char oldstring[256]; /*** this is where we store the old string ***/
char newstring[256]; /*** this is where we store the new string ***/
main()
{
Handle handle;
RememberA0();
SetUpA4();
/*** Detach this code resource so it stays where we can run it ***/
asm {
_RecoverHandle
move.l a0,handle
}
DetachResource(handle);
/*** save old trap number in address ***/
address=GetTrapAddress(TRAPNUM);
/*** set trap to my proc ***/
SetTrapAddress((long)&myproc,TRAPNUM);
/*** load old string and new string ***/
handle=GetNamedResource('STR ',"\pOld String");
PtoCstr(*handle);
strcpy(oldstring,*handle);
ReleaseResource(handle);
handle=GetNamedResource('STR ',"\pNew String");
PtoCstr(*handle);
strcpy(newstring,*handle);
ReleaseResource(handle);
/*** start at the beginning of the string ***/
pos=0;
RestoreA4();
}
pascal void myproc(c,h)
int c; /*** char variables are put on the stack as ints ***/
TEHandle h;
{
int x;
SetUpA4(); /*** so we can access globals ***/
/*** call the origional TEKey trap ***/
/*** if returning a value, use CallPascalB,W,L see p.125 of Think C manual ***/
CallPascal(c,h,address);
if (uppercase(c)==uppercase((int)oldstring[pos]))
{
++pos;
if (oldstring[pos]=='\0') /*** we got the whole string ***/
{
/*** erase old string ***/
for (x=1;x<=strlen(oldstring);++x)
CallPascal(8,h,address); /*** backspace ***/
/*** write the new string ***/
for (x=0;x<strlen(newstring);++x)
CallPascal((int)newstring[x],h,address);
pos=0;
}
}
else pos=0;
RestoreA4();
}